// extract module
var fs = require('fs');

// read file
try {
  var data = fs.readFileSync('textfile1.txt', 'utf8');
  console.log(data);
}
catch (e) {
  console.log('readFileSync error: ', e);
}

fs.readFile('textfile1.txt', 'utf8', function(error, data) {
  if (error) {
    console.log('readFile error: ', error);
  }
  else {
    console.log(data);
  }
});

// write file
try {
  fs.writeFileSync('E:\\textfile.txt', 'HelloWorld..!', 'utf8');
  console.log('FILE WRITE COMPLETE');
}
catch (e) {
  console.log('writeFileSync error: ', e);
}

fs.writeFile('E:\\textfile.txt', 'HelloWorld..!', 'utf8', function(error) {
  if (error) {
    console.log('writFile error: ', error);
  }
  else {
    console.log('FILE WRITE COMPLETE');
  }
});